﻿#ifndef __SS_DYNAMIC_LIBRARY_H__
#define __SS_DYNAMIC_LIBRARY_H__

namespace StarSeeker
{

#ifdef _WIN32

#include <windows.h>
typedef HMODULE DllType;
#define LoadDLL(_Name) LoadLibraryExA( _Name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
#define UnloadDLL(_DLLType) (FreeLibrary( _DLLType ) == TRUE)
#define GetDLLFunction( _DLLType , _FuncName ) reinterpret_cast<void*>(GetProcAddress( _DLLType , _FuncName ))
#define SS_DLL_EXT ".dll"

#else

#include <dlfcn.h>
typedef void* DllType;
#define LoadDLL(_Name) dlopen( _Name, RTLD_LAZY | RTLD_GLOBAL )
#define UnloadDLL(_DLLType) dlclose( _DLLType )
#define GetDLLFunction( _DLLType, _FuncName ) dlsym( _DLLType, _FuncName )
#define SS_DLL_EXT ".so"

#endif

class ssDynamicLibrary
{
public:
	ssDynamicLibrary();
	ssDynamicLibrary(const char* name);
	~ssDynamicLibrary();
	bool Load(const char* name);
	void* GetFuncPtr(const char* name);
	bool Unload();
	bool IsLoad(){return m_dll != 0;}
private:
	DllType m_dll;
};


}
#endif
